package com.czy.designPatterns.监听者模式.java;

import org.assertj.core.util.Lists;

import java.util.EventListener;
import java.util.List;

/**
 * 事件源
 * @Author: czy
 * @Date: 2019/6/6 9:05
 */
public class Kid {
    private String name;
    /**
     * 监听集合
     */
    private List<EventListener> liteners;
    public Kid(String name) {
        this.name = name;
        this.liteners = Lists.newArrayList();
    }
    public void eat(WashingHandsEvent eventObject){
        for(EventListener listener:liteners){
            if(listener instanceof WashingHandsListener){
                WashingHandsListener washingHandsListener = (WashingHandsListener) listener;
                washingHandsListener.fireAfterEventInvoked(eventObject);
            }
        }
        System.out.println("吃饭...");
    }
    //添加监听的方法
    public void addListener(EventListener listener){
        liteners.add(listener);
    }
}
